import com.googlecode.lightest.core.LightestTestCase
import com.googlecode.lightest.studio.Profile

class ProfileController {

    def scaffold = Profile

    /**
     * Refreshing the Profile means re-scanning all related test directories
     * for modifications to Test's, and updating Test's accordingly.
     */
    def refresh = {
        def dirs = testDirs.collect { new File(it.dir) }
        def classLoader = Thread.currentThread.contextClassLoader

        for (dir in dirs) {
            if (! dir.isDirectory()) {
                continue
            }

            dir.eachFileRecurse { file ->
                if (file.name.endsWith('.groovy')) {
                    try {
                        def testClass = classLoader.parseClass(file)
                        if (testClass instanceof LightestTestCase) {
                            // update Test store with test details
                        }
                    }
                    catch (e) {
                        // log something about compilation failed, etc.
                    }
                }
            }
        }

        // leave some message about how many tests were found, how many were
        // updated, removed, etc.
    }
}
